#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

const int N = 2e5 + 10;

int t;
int n;
int in[N];
vector<pii> e[N];
struct node {
    int a, b, c, idx;
}g[N];
map<int, int> mp;
void dfs(int u, int col) {
    for (auto i : e[u]) {
        int se = i.second;
        if (!mp[se]) {
            if (col == 2) {
                mp[se] = 2;
                dfs(i.first, 5);
            } else {
                mp[se] = 5;
                dfs(i.first, 2);
            }
        }
    }
}

void clear_graph() {
    for (int i = 0; i < n*2; i++) {
        e[i].clear();
        in[i] = 0;
    }
    mp.clear();
}
int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    cin >> t;
    while (t--) {
        cin >> n;
        clear_graph();
        for (int i = 1; i <= n - 1; i++) {
            int u, v;
            cin >> u >> v;
            g[i] = {u, v, 0, i};
            in[u]++, in[v]++, e[u].push_back({v, i}), e[v].push_back({u, i});
        }
        bool flag = true;
        int start = 0;
        for (int i = 1; i <= n; i++) {
            if (in[i] >= 3) {
                flag = false;
                break;
            }

            if (in[i] == 1) {
                start = i;
            }
        }

        if (!flag) {
            cout << -1 << endl;
            continue;
        }

        dfs(start, 2);
        for (int i = 1; i <= n-1; i++) {
            cout << mp[i] << ' ';
        }
        cout << endl;
    }
    return 0;
}